﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ActivePalControls
{
    /// <summary>
    /// Interaction logic for TiteledProgressBar.xaml
    /// </summary>
    public partial class TitledProgressBar : UserControl
    {
        #region Properties

        /// <summary>
        /// Returns control progress bar element
        /// </summary>
        public Control ProgressBar { get { return pbMain; } }

        /// <summary>
        /// Returns control text box element
        /// </summary>
        public TextBlock TextblockMajor { get { return tblockMajor; } }

        /// <summary>
        /// Returns control text box element
        /// </summary>
        public TextBlock TextblockMinor { get { return tblockMinor; } } 

        #endregion
                
        /// <summary>
        /// Creates new instance, clears inner control states to default 
        /// </summary>
        public TitledProgressBar()
        {
            InitializeComponent();
            ClearToDefault();
        }

        /// <summary>
        /// Update the value property of Progress bar
        /// </summary>
        /// <param name="min">minimum value</param>
        /// <param name="max">maximum value</param>
        /// <param name="current">current value</param>
        public void UpdateProgressBar(int min, int max, int current)
        {            
            double value = current / (max - min);

            if (value > pbMain.Maximum)
            {
                value = pbMain.Maximum;
            }

            pbMain.Value = value;
        }

        /// <summary>
        /// Sets Text properties for labels controls
        /// </summary>        
        public void UpdateControlLabels(string majorText, string minorText)
        {
            SetDefaultText();

            tblockMajor.Text += majorText;
            tblockMinor.Text += minorText;
        }

        /// <summary>
        /// Sets value to progressbar and labels
        /// </summary>
        /// <param name="progressPercentage">from 0 to 100</param>
        /// <param name="majorText">label text</param>
        /// <param name="minorText">label text</param>
        public void UpdateControl(int progressPercentage, string majorText, string minorText)
        {
            SetDefaultText();

            tblockMajor.Text += majorText;
            tblockMinor.Text += minorText;

            pbMain.Value = progressPercentage;
        }

        /// <summary>
        /// Sets defauls text properties for labels
        /// </summary>
        private void SetDefaultText()
        {
            tblockMajor.Text = "Progress action: ";
            tblockMinor.Text = "Minor action: ";
        }

        /// <summary>
        /// Sets default lables' text, progress value to 0
        /// </summary>
        public void ClearToDefault()
        {
            SetDefaultText();
            pbMain.Value = 0;
        }
    }
}
